/**
 * woon 20160722
 */
var deviceone = require("deviceone");
var nf = deviceone.sm("do_Notification");
var dialog = deviceone.sm("do_Dialog");
var page = deviceone.sm("do_Page");
var http = require("helper/http");
var urlUser = require("url/user");
var httpSilence = require("helper/httpSilence");//没有等提示

//添加好友申请
function addFriendApply(friendId,callBack){
	if(friendId==null && friendId=="undefined"){
		nf.toast("对方用户id为空");
		return;
	}
	var data1 = {title : "留言",	hint : "给对方说点什么吧 【最多10个字】", limit: 10}
	dialog.open("source://view/reuse/popInput/pop_input.ui", data1, function(returnText, e) {
		page.hideKeyboard();
		if (!returnText){
			returnText = "";
		}
		http.post(urlUser.url.friendApply.add, {friendId: friendId, message: returnText}, function(data) {
			if(callBack && callBack!=null && callBack!="undefined"){
				callBack();
			}else{
				nf.toast("已成功提交好友申请");
			}
		});
	});
	
}

//删除好友
function deleteFriend(friendId,callBack){
	if(friendId==null && friendId=="undefined"){
		nf.toast("好友用户id为空");
		return;
	}
	http.post(urlUser.url.friend.del, {friendId: friendId}, function(data) {
		if(callBack && callBack!=null && callBack!="undefined"){
			callBack();
		}else{
			nf.toast("删除好友成功");
		}
	});
}

//接受好友申请
function acceptFriendApply(friendApplyId,callBack){
	if(friendApplyId==null && friendApplyId=="undefined"){
		nf.toast("好友申请id为空");
		return;
	}
	http.post(urlUser.url.friendApply.accept, {id: friendApplyId}, function(data) {
		if(callBack && callBack!=null && callBack!="undefined"){
			callBack();
		}else{
			nf.toast("已成功接受好友友申请");
		}
	});
}

//忽略好友申请
function ignoreFriendApply(friendApplyId,callBack){
	if(friendApplyId==null && friendApplyId=="undefined"){
		nf.toast("好友申请id为空");
		return;
	}
	http.post(urlUser.url.friendApply.ignore, {id: friendApplyId}, function(data) {
		if(callBack && callBack!=null && callBack!="undefined"){
			callBack();
		}else{
			nf.toast("已忽略好友申请");
		}
	});
}

//是否我的好友
function isMyFriend(userId,callBack){
	if(userId==null && userId=="undefined"){
		nf.toast("对方用户id为空");
		return;
	}
	httpSilence.post(urlUser.url.friendApply.checkFriend, {friendId: userId}, function(data) {
		if(data.isMyFriend){
			if(callBack && callBack!=null && callBack!="undefined"){
				callBack();
			}else{
				nf.toast("你们是好友！");
			}
		}else{
			nf.toast("你们不是好友！");
		}
		
	});
}

//删除好友申请
function removeFriendApply(friendApplyId,callBack){
	if(friendApplyId==null && friendApplyId=="undefined"){
		nf.toast("好友申请id为空");
		return;
	}
	http.post(urlUser.url.friendApply.remove, {id: friendApplyId}, function(data) {
		if(callBack && callBack!=null && callBack!="undefined"){
			callBack();
		}else{
			nf.toast("已删除好友申请");
		}
	});
}

module.exports.addFriendApply = addFriendApply;
module.exports.deleteFriend = deleteFriend;

module.exports.acceptFriendApply = acceptFriendApply;
module.exports.ignoreFriendApply = ignoreFriendApply;

module.exports.isMyFriend = isMyFriend;
module.exports.removeFriendApply = removeFriendApply;


